<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script>
  var worker = new Worker('worker.js');

  function createWorker() {

    worker.postMessage('Work done!');
    worker.onmessage = function (event) {
      console.log('Received message ' + event.data);
      doSomething();
    };

    function doSomething() {
      console.log('-------');
      // 执行任务
      worker.postMessage('Work done!');
      // 关闭线程
    }
    setTimeout(createWorker, 1000)
  }

  createWorker();

</script>
</body>
</html>
